package com.hcbd.tdwt.ui.xingyu.fragment;

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


import com.hcbd.tdwt.R;
import com.hcbd.tdwt.base.BaseFragment;
import com.hcbd.tdwt.base.Listener.InfoInterface;
import com.hcbd.tdwt.base.bd.BdToolFactory;
import com.pangu.bdsdk2021.entity.terminaltwo.BDGGAInfo;
import com.pangu.bdsdk2021.entity.terminaltwo.BDRMCInfo;
import com.hcbd.tdwt.ui.xingyu.adapter.SatelliteListAdapter;
import com.hcbd.tdwt.ui.xingyu.vo.SatelliteVO;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;
import java.util.List;

@SuppressLint("NonConstantResourceId")
@EFragment(R.layout.fragment_satellite_list)
public class SatelliteListFragment extends BaseFragment implements InfoInterface {
    @ViewById
    RecyclerView satelliteRV;
    @ViewById
    View view_1,view_2,view_3,view_4;
    @ViewById
    ImageView satelliteImg,signalImg,halfCircleImg,elevationImg;
    @ViewById
    LinearLayout topLL;

    private List<SatelliteVO> satelliteVOList;
    private SatelliteListAdapter satelliteListAdapter;

    @AfterViews
    protected void init() {
        satelliteVOList=new ArrayList<>();
        if(BdToolFactory.app_type!=BdToolFactory.XY_BG_TYPE&&BdToolFactory.app_type!=BdToolFactory.XY_PDA_BG_TYPE){
            view_1.setBackground(getContext().getDrawable(R.color.backgroundMain));
            view_2.setBackground(getContext().getDrawable(R.color.backgroundMain));
            view_3.setBackground(getContext().getDrawable(R.color.backgroundMain));
            view_4.setBackground(getContext().getDrawable(R.color.backgroundMain));
            satelliteRV.setBackground(getContext().getDrawable(R.color.white));
            topLL.setBackground(getContext().getDrawable(R.color.white));
            satelliteImg.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.satellite_grey));
            signalImg.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.signal_grey));
            halfCircleImg.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.elevation_grey));
            elevationImg.setImageDrawable(ContextCompat.getDrawable(getContext(),R.drawable.half_circle_grey));
        }
    }
    void initSatelliteAdapter(){
        if ( null!=satelliteVOList&& satelliteVOList.size()>0) {
            if (null == satelliteListAdapter) {
                satelliteListAdapter = new SatelliteListAdapter(this.getActivity(), satelliteVOList);
                satelliteListAdapter.setHasStableIds(true);
            } else {
                satelliteListAdapter.notifyDataSetChanged(satelliteVOList);
                return;
            }
            GridLayoutManager gridLayoutManager = new GridLayoutManager(this.getActivity(), 1);
            satelliteRV.setLayoutManager(gridLayoutManager);
            satelliteRV.setAdapter(satelliteListAdapter);
        }
    }
    @Override
    public void onGSVInfo(List<SatelliteVO> satelliteVOS) {
        if(satelliteRV!=null){
            satelliteVOList=satelliteVOS;
            initSatelliteAdapter();
        }

    }

    @Override
    public void onGGAInfo(BDGGAInfo bdggaInfo) {

    }

    @Override
    public void onRMCInfo(BDRMCInfo bdrmcInfo) {

    }
}
